import axios from '@/utils/request'
import {ref} from 'vue'

let roleId = ref('')

//请求角色信息
export async function getRolesInfo(){
    let getRolesInfo = await axios.get('/index/roles/getRolesInfo')
    return getRolesInfo
}

//更新、新增、删除权限组
export async function editRoleInfo(type,form){
    let data = {
        submitType:type,
        submitForm:form
    }   
    let newRoles = await axios.post('/index/roles/editRolesInfo',data)
    return newRoles
}

//请求已存在的权限
export async function hasAuthoritysInfo(id){
    // console.log(id);   
    roleId.value = id
    let hasAuthoritysInfo = await axios.get(`/index/roles/hasAuthoritysInfo?id=${id}`)
    return hasAuthoritysInfo
}

//分配权限明细/用户
export async function changeRole(type,form){
    let urlStr = type.includes("Auth") ? "Auth" : type.includes("User") ? "User" : ""
    let data = {
        roleId:roleId.value,
        submitType:type,
        submitForm:form
    }   
    let newRoles = await axios.post(`/index/Roles/changeRole${urlStr}`,data)
    return newRoles
}

//请求已存在的用户
export async function hasUsersInfo(id){
    roleId.value = id
    let hasUsersInfo = await axios.get(`/index/roles/hasUsersInfo?id=${id}`)
    return hasUsersInfo
}
